//
//  AppDelegate.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/5/21.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "AppDelegate.h"



BMKMapManager* _mapManager;


@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
  
    
    
  
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor blackColor];
    
    
    
//    // 要使用百度地图，请先启动BaiduMapManager
//    _mapManager = [[BMKMapManager alloc]init];
//    BOOL ret = [_mapManager start:@"RTqaMlGlwLoeEFaTmbDFk6is" generalDelegate:self];
//    
//    if (!ret) {
//        NSLog(@"manager start failed!");
//    }
//
//    
//    FirstPageViewController *firstVC = [[FirstPageViewController alloc] init];
//    UINavigationController *firstNAVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
//    firstNAVC.navigationBar.translucent = NO;
//    firstVC.view.tag = 1001;
//    firstNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"shouye.png"] tag:1001];
//
//    
//    self.shopVC = [[ShoppingViewController alloc] init];
//    UINavigationController  *shopNAVC = [[UINavigationController alloc]initWithRootViewController:self.shopVC];
//    shopNAVC.navigationBar.translucent = NO;
//    shopNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"car.png"] tag:1002];
//    shopNAVC.tabBarItem.badgeValue = @"10";
//    
//    MyselfViewController *myVC = [[MyselfViewController alloc] init];
//    UINavigationController *myNAVC = [[UINavigationController alloc] initWithRootViewController:myVC];
//    myNAVC.navigationBar.translucent = NO;
////    UIImage *meImage = [UIImage imageNamed:@"me@2x.png"];
////    meImage = [meImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    myNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"me.png"] tag:1003];
//    
//    
//    //创建tabBarController
//    self.tabBarController = [[UITabBarController alloc] init];
//    self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstNAVC, shopNAVC, myNAVC, nil];
//    self.tabBarController.delegate = self;
//    self.window.rootViewController = self.tabBarController;
//    
//    self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
//    self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
////    self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
//    //tabBar不透明
//    self.tabBarController.tabBar.translucent = YES;
    // 判断是不是第一次启动应用
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        
        // iPhone4的适配
        if ([[UIScreen mainScreen] bounds].size.width == 320 && [[UIScreen mainScreen] bounds].size.height == 480) {
            
            NSArray *backgroundImageNames = @[@"guidanceBack1", @"guidanceBack2", @"guidanceBack3"];
            NSArray *coverImageNames = @[@"guidance_4@2x", @"guidance1_4@2x", @"guidance2_4@2x"];
            self.intro = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
            
            
            // iPhone5、5s的适配
        }else if ([[UIScreen mainScreen] bounds].size.width == 320 && [[UIScreen mainScreen] bounds].size.height == 568){
            
            NSArray *backgroundImageNames = @[@"guidanceBack1", @"guidanceBack2", @"guidanceBack3"];
            NSArray *coverImageNames = @[@"guidance_5@2x", @"guidance1_5@2x", @"guidance2_5@2x", @"guidance3_4@2x.png"];
            self.intro = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
            
            // iPhone6的适配
        }else if ([[UIScreen mainScreen] bounds].size.width == 375 && [[UIScreen mainScreen] bounds].size.height == 667){
            
            NSArray *backgroundImageNames = @[@"guidanceBack1", @"guidanceBack2", @"guidanceBack3", @"guidance3_5@2x.png"];
            NSArray *coverImageNames = @[@"guidance_6@2x", @"guidance1_6@2x", @"guidance2_6@2x", @"guidance3_6@2x.png"];
            self.intro = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
            
            // iPhone6plus的适配
        }else if ([[UIScreen mainScreen] bounds].size.width == 414 && [[UIScreen mainScreen] bounds].size.height == 736){
            
            NSArray *backgroundImageNames = @[@"guidanceBack1", @"guidanceBack2", @"guidanceBack3"];
            NSArray *coverImageNames = @[@"guidance_6plus@3x", @"guidance1_6plus@3x", @"guidance2_6plus@3x", @"guidance3_6plus@3x"];
            self.intro = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
        }
        
            // 要使用百度地图，请先启动BaiduMapManager
            _mapManager = [[BMKMapManager alloc]init];
            BOOL ret = [_mapManager start:@"RTqaMlGlwLoeEFaTmbDFk6is" generalDelegate:self];
        
            if (!ret) {
                NSLog(@"manager start failed!");
            }
        
        
            FirstPageViewController *firstVC = [[FirstPageViewController alloc] init];
            UINavigationController *firstNAVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
            firstNAVC.navigationBar.translucent = NO;
            firstVC.view.tag = 1001;
            firstNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"shouye.png"] tag:1001];
        
        
            self.shopVC = [[ShoppingViewController alloc] init];
            UINavigationController  *shopNAVC = [[UINavigationController alloc]initWithRootViewController:self.shopVC];
            shopNAVC.navigationBar.translucent = NO;
            shopNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"car.png"] tag:1002];
            shopNAVC.tabBarItem.badgeValue = @"10";
        
            MyselfViewController *myVC = [[MyselfViewController alloc] init];
            UINavigationController *myNAVC = [[UINavigationController alloc] initWithRootViewController:myVC];
            myNAVC.navigationBar.translucent = NO;
        //    UIImage *meImage = [UIImage imageNamed:@"me@2x.png"];
        //    meImage = [meImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            myNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"me.png"] tag:1003];
        
        
            //创建tabBarController
            self.tabBarController = [[UITabBarController alloc] init];
            self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstNAVC, shopNAVC, myNAVC, nil];
            self.tabBarController.delegate = self;
            self.window.rootViewController = self.tabBarController;
        
            self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
            self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
        //    self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
            //tabBar不透明
            self.tabBarController.tabBar.translucent = YES;
        [self.window makeKeyAndVisible];
        
        [self.window addSubview:self.intro.view];
        
        
        
    }else{
        
        
            // 要使用百度地图，请先启动BaiduMapManager
            _mapManager = [[BMKMapManager alloc]init];
            BOOL ret = [_mapManager start:@"RTqaMlGlwLoeEFaTmbDFk6is" generalDelegate:self];
        
            if (!ret) {
                NSLog(@"manager start failed!");
            }
        
        
            FirstPageViewController *firstVC = [[FirstPageViewController alloc] init];
            UINavigationController *firstNAVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
            firstNAVC.navigationBar.translucent = NO;
            firstVC.view.tag = 1001;
            firstNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"shouye.png"] tag:1001];
        
        
            self.shopVC = [[ShoppingViewController alloc] init];
            UINavigationController  *shopNAVC = [[UINavigationController alloc]initWithRootViewController:self.shopVC];
            shopNAVC.navigationBar.translucent = NO;
            shopNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"car.png"] tag:1002];
            shopNAVC.tabBarItem.badgeValue = @"10";
        
            MyselfViewController *myVC = [[MyselfViewController alloc] init];
            UINavigationController *myNAVC = [[UINavigationController alloc] initWithRootViewController:myVC];
            myNAVC.navigationBar.translucent = NO;
        //    UIImage *meImage = [UIImage imageNamed:@"me@2x.png"];
        //    meImage = [meImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            myNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"me.png"] tag:1003];
        
        
            //创建tabBarController
            self.tabBarController = [[UITabBarController alloc] init];
            self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstNAVC, shopNAVC, myNAVC, nil];
            self.tabBarController.delegate = self;
            self.window.rootViewController = self.tabBarController;
        
            self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
            self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
        //    self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
            //tabBar不透明
            self.tabBarController.tabBar.translucent = YES;
        
        [self.window makeKeyAndVisible];
        
        
    }
    
    __weak AppDelegate *weakSelf = self;
    self.intro.didSelectedEnter = ^() {
        [weakSelf.intro.view removeFromSuperview];
        weakSelf.intro = nil;
        
        // enter main view , write your code ...
        
    };

    
    return YES;
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    
     [BMKMapView willBackGround];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    
     [BMKMapView didForeGround];//百度地图API
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


//代理方法
- (void)onGetNetworkState:(int)iError
{
    if (0 == iError) {
        NSLog(@"联网成功");
    }
    else{
        NSLog(@"onGetNetworkState %d",iError);
    }
    
}

- (void)onGetPermissionState:(int)iError
{
    if (0 == iError) {
        NSLog(@"授权成功");
    }
    else {
        NSLog(@"onGetPermissionState %d",iError);
    }
}

@end
